package huaabdelmartin;


public class Journey {
	/**
	 * Instance variables
	 */
	private Integer year;
	private Car taxi;
	private Destination destination;
	private Integer numberPassengers; 

	/**
	 * Constructor
	 */
	public Journey(Integer year, Car taxi, Destination destination, Integer numberPassengers) {
		this.year = year;
		this.taxi = taxi;
		this.destination = destination;
		this.numberPassengers = numberPassengers;
	}

	/**
	 * getters and setters
	 * @return
	 */
	public Integer getNumberPassengers() {
		return numberPassengers;
	}
	public void setNumberPassengers(Integer numberPassengers) {
		this.numberPassengers = numberPassengers;
	}

	public Integer getYear() {
		return year;
	}
	public void setYear(Integer year) {
		this.year = year;
	}
	public Car getTaxi() {
		return taxi;
	}
	public void setTaxi(Car taxi) {
		this.taxi = taxi;
	}
	public Destination getDestination() {
		return destination;
	}
	public void setDestination(Destination destination) {
		this.destination = destination;
	}

	public Double getJourneyCost(){
		//1 p/mile p/person, and for each person reduce by 10%
		Double cost = 0.0;
		cost =  destination.getDistance() * 1.0 * numberPassengers ;
		Double discount = 0.0;
		discount = 0.1 * numberPassengers;
		cost = cost - ( cost * discount );
		return cost;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((destination == null) ? 0 : destination.hashCode());
		result = prime
				* result
				+ ((numberPassengers == null) ? 0 : numberPassengers.hashCode());
		result = prime * result + ((taxi == null) ? 0 : taxi.hashCode());
		result = prime * result + ((year == null) ? 0 : year.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Journey other = (Journey) obj;
		if (destination == null) {
			if (other.destination != null)
				return false;
		} else if (!destination.equals(other.destination))
			return false;
		if (numberPassengers == null) {
			if (other.numberPassengers != null)
				return false;
		} else if (!numberPassengers.equals(other.numberPassengers))
			return false;
		if (taxi == null) {
			if (other.taxi != null)
				return false;
		} else if (!taxi.equals(other.taxi))
			return false;
		if (year == null) {
			if (other.year != null)
				return false;
		} else if (!year.equals(other.year))
			return false;
		return true;
	}
	public String toString(){
		return "Destination: "+destination.getNameOfDestination();
	}

}
